# -*- coding: utf-8 -*-

import abc

from daemonize_worker import DaemonizeWorker


class ConveyorDrivenWorker(DaemonizeWorker):

    def _run(self, params=None):
        msg = []
        try:
            msg = self._components['conveyor'].receive()
        except Exception as e:
            self.logger.error('[conveyor receiving]: %s' % e)
            if self._cfg.get('raise_conveyor_exception', False) is True:
                raise e
        if not msg:
            return

        self._process_task_msg(msg, params)

    @abc.abstractmethod
    def _process_task_msg(self, msg, params=None):
        raise NotImplementedError('call to abstract method %s._process_task_msg' % (self.__class__,))

    # @abc.abstractmethod
    # def _parse_task_msg(self, msg):
    #     raise NotImplementedError('call to abstract method %s._parse_task_msg' % (self.__class__,))
